<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单系统架构设计</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 0.875rem;
            line-height: 1.5;
        }
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            width: 3rem;
            height: 3rem;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            font-weight: bold;
            font-size: 1.25rem;
        }
        .timeline-line {
            background: linear-gradient(to bottom, #667eea, #764ba2);
            width: 2px;
            position: absolute;
            left: 1.5rem;
            top: 3rem;
            bottom: 0;
        }
        .section-title {
            position: relative;
            display: inline-block;
            padding-bottom: 0.5rem;
        }
        .section-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 3px;
            background: linear-gradient(to right, #667eea, #764ba2);
            border-radius: 2px;
        }
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        .highlight-text {
            background: linear-gradient(to right, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    <i class="fas fa-shopping-cart mr-4"></i>订单系统架构设计
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">从用户请求到订单完成的完整技术实现</p>
                <div class="flex justify-center space-x-8 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-code mr-2"></i>
                        <span>7个核心步骤</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>高并发处理</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-chart-line mr-2"></i>
                        <span>实时监控</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- System Architecture Diagram -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <h2 class="section-title text-3xl font-bold mb-8">系统架构概览</h2>
            <div class="mermaid">
                graph TB
                    A[用户界面] -->|HTTP请求| B[API网关]
                    B --> C[订单服务]
                    C --> D[库存服务]
                    C --> E[支付服务]
                    C --> F[通知服务]
                    D --> G[(Redis缓存)]
                    D --> H[(MySQL数据库)]
                    E --> I[支付网关]
                    F --> J[邮件/短信服务]
                    C --> K[消息队列]
                    K --> L[日志服务]
                    K --> M[监控服务]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style G fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                    style H fill:#3b82f6,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16">
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Left Sidebar - Quick Navigation -->
            <aside class="lg:col-span-1">
                <div class="bg-white rounded-xl shadow-lg p-6 sticky top-6">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-compass mr-2 text-purple-600"></i>快速导航
                    </h3>
                    <nav class="space-y-3">
                        <a href="#step1" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-user mr-2 text-purple-500"></i>用户发起请求
                        </a>
                        <a href="#step2" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-server mr-2 text-purple-500"></i>服务器接收
                        </a>
                        <a href="#step3" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-warehouse mr-2 text-purple-500"></i>库存检查
                        </a>
                        <a href="#step4" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-file-invoice mr-2 text-purple-500"></i>创建订单
                        </a>
                        <a href="#step5" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-credit-card mr-2 text-purple-500"></i>支付处理
                        </a>
                        <a href="#step6" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-bell mr-2 text-purple-500"></i>订单确认
                        </a>
                        <a href="#step7" class="block p-3 rounded-lg hover:bg-purple-50 transition-colors">
                            <i class="fas fa-chart-bar mr-2 text-purple-500"></i>日志监控
                        </a>
                    </nav>
                </div>
            </aside>

            <!-- Main Content Area -->
            <div class="lg:col-span-2 space-y-12">
                <!-- Step 1 -->
                <section id="step1" class="relative">
                    <div class="timeline-line"></div>
                    <div class="flex items-start">
                        <div class="step-number">1</div>
                        <div class="ml-8 flex-1">
                            <h3 class="text-2xl font-bold mb-4">用户发起订单请求</h3>
                            
                            <div class="bg-white rounded-xl shadow-lg p-6 mb-6 card-hover">
                                <h4 class="text-lg font-semibold mb-3 flex items-center">
                                    <i class="fas fa-mouse-pointer mr-2 text-purple-600"></i>用户操作
                                </h4>
                                <p class="text-gray-700 mb-4">用户在前端页面选择商品并提交订单请求，系统需要准确捕获用户意图。</p>
                                <div class="code-block">
                                    <pre><code>&lt;!-- 用户提交订单请求 --&gt;
&lt;form id="order-form"&gt;
    &lt;input type="hidden" name="productId" value="12345"&gt;
    &lt;input type="hidden" name="quantity" value="2"&gt;
    &lt;button type="submit"&gt;提交订单&lt;/button&gt;
&lt;/form&gt;</code></pre>
                                </div>
                            </div>

                            <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                                <h4 class="text-lg font-semibold mb-3 flex items-center">
                                    <i class="fas fa-code mr-2 text-purple-600"></i>前端处理
                                </h4>
                                <p class="text-gray-700 mb-4">使用AJAX技术异步提交订单，提升用户体验。</p>
                                <div class="code-block">
                                    <pre><code>// 使用AJAX提交订单
$.ajax({
    url: '/api/order',
    type: 'POST',
    data: {
        productId: 12345,
        quantity: 2
    },
    success: function(response) {
        // 处理服务器返回的结果
    }
});</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>

                <!-- Step 2 -->
                <section id="step2" class="relative">
                    <div class="timeline-line"></div>
                    <div class="flex items-start">
                        <div class="step-number">2</div>
                        <div class="ml-8 flex-1">
                            <h3 class="text-2xl font-bold mb-4">服务器接收请求</h3>
                            
                            <div class="bg-white rounded-xl shadow-lg p-6 mb-6 card-hover">
                                <h4 class="text-lg font-semibold mb-3 flex items-center">
                                    <i class="fas fa-network-wired mr-2 text-purple-600"></i>请求接收
                                </h4>
                                <p class="text-gray-700 mb-4">服务器通过RESTful API接收订单请求，使用Spring MVC框架处理。</p>
                                <div class="code-block">
                                    <pre><code>@RestController
@RequestMapping("/api/order")
public class OrderController {

    @PostMapping
    public ResponseEntity&lt;OrderResponse&gt; createOrder(@RequestBody OrderRequest orderRequest) {
        // 处理订单创建逻辑
    }
}</code></pre>
                                </div>
                            </div>

                            <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                                <h4 class="text-lg font-semibold mb-3 flex items-center">
                                    <i class="fas fa-shield-alt mr-2 text-purple-600"></i>请求验证
                                </h4>
                                <p class="text-gray-700 mb-4">严格验证请求参数，确保数据的完整性和安全性。</p>
                                <div class="code-block">
                                    <pre><code>// 验证请求参数
if (orderRequest.getQuantity() &lt;= 0 || !productExists(orderRequest.getProductId())) {
    return ResponseEntity.badRequest().body(new OrderResponse("Invalid request"));
}</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>

                <!-- Step 3 -->
                <section id="step3" class="relative">
                    <div class="timeline-line"></div>
                    <div class="flex items-start">
                        <div class="step-number">3</div>
                        <div class="ml-8 flex-1">
                            <h3 class="text-2xl font-bold mb-4">库存检查与锁定</h3>
                            
                            <div class="bg-white rounded-xl shadow-lg p-6 mb-6 card-hover">
                                <h4 class="text-lg font-semibold mb-3 flex items-center">
                                    <i class="fas fa-database mr-2 text-purple-600"></i>库存查询
                                </h4>
                                <p class="text-gray-700 mb-4">使用Redis缓存提高库存查询性能，减少数据库压力。</p>
                                <div class="code-block">
                                    <pre><code>// 查询商品库存
Integer stock = redisTemplate.opsForValue().get("product:stock:" + orderRequest.getProductId());</code></pre>
                                </div>
                            </div>

                            <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                                <h4 class="text-lg font-semibold mb-3 flex items-center">
                                    <i class="fas fa-lock mr-2 text-purple-600"></i>分布式锁
                                </h4>
                                <p class="text-gray-700 mb-4">使用Redisson分布式锁防止高并发下的